package com.ruiya.staging.goods.locate.controller;

import com.ruiya.staging.goods.core.constants.ErrorCodeEnum;
import com.ruiya.staging.goods.core.model.GoodsIdVO;
import com.ruiya.staging.goods.core.model.RestResponse;
import com.ruiya.staging.goods.locate.service.TestService;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@Deprecated
@RestController
public class TestController {

    @Autowired
    private TestService testService;

    @GetMapping("/test/locate/{goodsNo}")
    public RestResponse<GoodsIdVO> locate(@PathVariable("goodsNo") String goodsNo) {
        String tid = UUID.randomUUID().toString();
        if (StringUtils.isEmpty(goodsNo)) {
            return new RestResponse<>(ErrorCodeEnum.PARAMSERROR.getCode(), "goodsNo不能为空", tid);
        }

        Pair<ErrorCodeEnum, GoodsIdVO> result = this.testService.locateGoodsId(tid, goodsNo);
        if(result.getKey().isFail()){
            return new RestResponse<>(result.getKey(), tid);
        }

        GoodsIdVO goodsIdVO = result.getValue();
        return new RestResponse<>(goodsIdVO);
    }

}
